<template>
  <el-container style="height: 100vh" v-if="token && token != ''">
    <el-aside width="auto">
      <side-bar></side-bar>
    </el-aside>
    <el-container>
      <el-header style="padding: 0 15px">
        <NavigateBar />
      </el-header>
      <el-main style="background: #f5f5f5; padding: 0">
        <el-scrollbar class="pd15">
          <router-view></router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
  <router-view v-else></router-view>
</template>

<script>
import { reactive, toRefs, computed } from "vue";
import SideBar from "@/components/SideBar.vue"; //页面左侧栏目
import NavigateBar from "@/components/NavigateBar.vue"; //页面顶部固定
import { useRouter } from "vue-router";
import { useStore } from "vuex";
export default {
  name: "Main",
  components: {
    SideBar,
    NavigateBar,
  },
  setup() {
    const router = useRouter();
    const store = useStore();
    const state = reactive({
      isLogin: true,
      token: computed(() => store.state.token), //vuex调用
    });
    const unwatch = router.beforeEach((to, from, next) => {
      if (to.path !== "/login" && (!state.token || state.token == ""))
        next({ path: "/login" });
      else next();
    });

    return {
      ...toRefs(state),
    };
  },
};
</script>

<style lang="scss" scoped>
</style>